<style>
  .el-dialog {
    width: 1100px;
  }
  .el-upload-list--picture .el-upload-list__item-name {
    width: 100px;
  }
  .el-button+.el-button {
    margin-left: 0 !important;
  }
  .customDialog {
    width: 49%;
  }
  .el-table__row{
    margin-top: 15px;
    border: 1px solid #e8e8e8;
  }
  .el-table::before {
    height: 0px;
  }
  .el-table .cell {
    word-break: keep-all;
  }
</style>
<template>
  <div>
    <div style="width: 100%;height: 100%">
      <!--&lt;!&ndash; 查询和其他操作 &ndash;&gt;-->
      <div style="width: 100%;">

        <div style="padding: 10px">
          <div style="padding-bottom: 10px">
            <el-button class="filter-item" type="primary" icon="el-icon-plus"
                       @click="handleAdd">添加企业
            </el-button>
          </div>

          <!-- 查询结果 -->
          <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row
                    :header-cell-style="{background:'#f5f5f5',color:'#666'}">
            <el-table-column align="center" min-width="120" label="统一信用代码" prop="unicode"/>
            <el-table-column align="center" min-width="150" label="公司名称" prop="companyName"/>
            <!--<el-table-column align="center" min-width="120" label="公司所属省份" prop="provinceName"/>
            <el-table-column align="center" min-width="140" label="公司详细地址" prop="address"/>-->
            <el-table-column align="center" min-width="120" label="中征码" prop="loanCardNo"/>
            <el-table-column align="center" min-width="80" label="法人姓名" prop="legalName"/>
            <!--<el-table-column align="center" min-width="140" label="法人证件号码" prop="legalID"/>-->
            <el-table-column align="center" min-width="100" label="法人手机号" prop="legalMobile"/>
            <el-table-column align="center" label="操作" width="110" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button type="text" size="mini" icon="el-icon-edit"
                           @click="handleEdit(scope.row)">修改
                </el-button>
                <el-button type="text" size="mini" icon="el-icon-share"
                           @click="signingAdd(scope.row)">签约
                </el-button>
                <!--<el-button type="warning" size="mini" plain
                           @click="particulars(scope.row)">查看详情
                </el-button>-->
                <el-popover
                  placement="top"
                  width="200"
                  trigger="manual"
                  :ref="'popover-' + scope.row.unicode">
                  <p>确定删除该数据吗？</p>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="$refs[`popover-` + scope.row.unicode].doClose()">取消</el-button>
                    <el-button type="primary" size="mini" @click="doDelete(scope.row)">确定</el-button>
                  </div>
                  <el-button type="text" size="mini" slot="reference" icon="el-icon-delete"
                             @click="$refs[`popover-` + scope.row.unicode].doShow()">删除</el-button>
                </el-popover>
              </template>
            </el-table-column>
          </el-table>

          <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize"
                      @pagination="getList"/>

          <!-- 添加/修改公司对话框 -->
          <el-dialog :visible.sync="editDialogVisible" :title="textMap[dialogStatus]" :close-on-click-modal="false">
            <el-form ref="editForm" :rules="editFormRules" :model="editForm" status-icon label-position="left"
                     label-width="165px" style="width: 1000px; margin-left:30px;display: flex">
              <div style="flex: 1;margin-right: 60px">
                <el-form-item label="统一信用代码" prop="unicode">
                  <el-input :disabled="dialogStatus=='update'" v-model="editForm.unicode" placeholder="请输入统一信用代码"/>
                </el-form-item>
                <el-form-item label="公司名称" prop="companyName">
                  <el-input v-model="editForm.companyName" auto-complete="off" placeholder="请输入公司名称"/>
                </el-form-item>
                <el-form-item label="公司所属省份" prop="province">
                  <el-cascader
                    style="width:100%"
                    :options="citys"
                    v-model="editForm.province"
                    @active-item-change="handleItemChange"></el-cascader>
                  <!--<el-cascader
                    style="width:100%"
                    :options="cities"
                    v-model="editForm.province"
                    :props="{ expandTrigger: 'hover',value:'value',label: 'label' }"
                  ></el-cascader>-->
                </el-form-item>
                <el-form-item label="公司详细地址" prop="address">
                  <el-input v-model="editForm.address" auto-complete="off" placeholder="请输入公司详细地址"/>
                </el-form-item>
                <el-form-item label="邮政编码" prop="postcode">
                  <el-input v-model="editForm.postcode" auto-complete="off" placeholder="请输入邮政编码"/>
                </el-form-item>
                <el-form-item label="行业分类" prop="industry">
                  <el-input v-model="editForm.industryName" readonly="readonly" placeholder="请选择行业分类" @click.native="getIndustry()"/>
                  <!--<el-select v-model="editForm.industry" placeholder="请选择" filterable>
                    <el-option
                      v-for="item in companys"
                      :key="item.number"
                      :label="item.name"
                      :value="item.number"
                    >
                    </el-option>
                  </el-select>-->
                </el-form-item>
                <el-form-item label="企业类型" prop="typeCode">
                  <el-select v-model="editForm.typeCode" placeholder="请选择" filterable>
                    <el-option
                      v-for="item in typeCode"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="企业细类" prop="detailCode">
                  <el-select v-model="editForm.detailCode" placeholder="请选择" filterable>
                    <el-option
                      v-for="item in CodeList"
                      :key="item.code"
                      :label="item.name"
                      :value="item.code"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="中征码" prop="loanCardNo">
                  <el-input v-model="editForm.loanCardNo" auto-complete="off" placeholder="请输入中征码"/>
                </el-form-item>
                <el-form-item label="法人姓名" prop="legalName">
                  <el-input v-model="editForm.legalName" auto-complete="off" placeholder="请输入法人姓名"/>
                </el-form-item>
                <el-form-item label="法定代表人身份证正面" prop="legalIDFront">
                  <el-upload
                    class="upload-demo"
                    ref="Front"
                    action="string"
                    :before-upload="beforeUploadFile"
                    :http-request="doFrontUpload"
                    :file-list="frontFileList"
                    :limit="1"
                    name="legalIDFront"
                    accept=".jpg,.jpeg,.png,.JPG,.JPEG,.PBG,"
                    list-type="picture"
                    :show-file-list = true>
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">图片文件（jpg、png、jpeg），2M以内</div>
                  </el-upload>
                </el-form-item>
                <el-form-item label="法定代表人身份证反面" prop="legalIDBack">
                  <el-upload
                    class="upload-demo"
                    ref="Back"
                    action="string"
                    :before-upload="beforeUploadFile"
                    :http-request="doBackUpload"
                    :file-list="backFileList"
                    :limit="1"
                    name="legalIDBack"
                    list-type="picture"
                    :show-file-list = true
                    accept=".jpg,.jpeg,.png,.JPG,.JPEG,.PBG,">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">图片文件（jpg、png、jpeg），2M以内</div>
                  </el-upload>
                </el-form-item>
              </div>
              <div style="flex: 1;">
                <el-form-item label="法人证件号码" prop="legalID">
                  <el-input v-model="editForm.legalID" auto-complete="off" placeholder="请输入法人证件号码"/>
                </el-form-item>
                <el-form-item label="法人手机号" prop="legalMobile">
                  <el-input v-model="editForm.legalMobile" auto-complete="off" placeholder="请输入法人手机号"/>
                </el-form-item>
                <el-form-item label="法人证件登记日期" prop="legalIDRegDate">
                  <el-date-picker
                    v-model="editForm.legalIDRegDate"
                    type="date"
                    placeholder="法人证件登记日期"
                    value-format="yyyy/MM/dd">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="法人证件到期日期" prop="legalIDExpiry">
                  <el-date-picker
                    v-model="editForm.legalIDExpiry"
                    type="date"
                    placeholder="法人证件到期日期"
                    value-format="yyyy/MM/dd">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="法人证件签发城市代码" prop="legalIDCity">
                  <!--<el-cascader
                    style="width:100%"
                    :options="citys"
                    v-model="editForm.legalIDCity"
                    @active-item-change="handleItemChange"></el-cascader>-->
                  <el-cascader
                    style="width:100%"
                    :options="cities"
                    v-model="editForm.legalIDCity"
                    :props="{ expandTrigger: 'hover',value:'value',label: 'label' }"
                  ></el-cascader>
                </el-form-item>
                <el-form-item label="企业统一执照扫描件" prop="businessLicense">
                  <el-upload
                    class="upload-demo"
                    ref="business"
                    action="string"
                    :before-upload="beforeUploadFile"
                    :http-request="doLicenseUpload"
                    :file-list="businessFileList"
                    :limit="1"
                    name="businessLicense"
                    list-type="picture"
                    :show-file-list = true
                    accept=".jpg,.jpeg,.png,.JPG,.JPEG,.PBG,">
                    <el-button size="small" type="primary">点击上传</el-button>
                    <div slot="tip" class="el-upload__tip">图片文件（jpg、png、jpeg），2M以内</div>
                  </el-upload>
                </el-form-item>
                <el-form-item label="执照证件注册日期" prop="certRegDate">
                  <el-date-picker
                    v-model="editForm.certRegDate"
                    type="date"
                    placeholder="执照证件注册日期"
                    value-format="yyyy/MM/dd">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="执照证件到期日期" prop="certExpiryDate">
                  <el-date-picker
                    v-model="editForm.certExpiryDate"
                    type="date"
                    placeholder="执照证件到期日期"
                    value-format="yyyy/MM/dd">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="股东名称" prop="gdcustomerName">
                  <el-input v-model="editForm.gdcustomerName" auto-complete="off" placeholder="请输入股东名称"/>
                </el-form-item>
                <el-form-item label="股东证件编号" prop="gdcertId">
                  <el-input v-model="editForm.gdcertId" auto-complete="off" placeholder="请输入股东证件编号"/>
                </el-form-item>
                <el-form-item label="股东证件登记日期" prop="gdregDate">
                  <el-date-picker
                    v-model="editForm.gdregDate"
                    type="date"
                    placeholder="股东证件登记日期"
                    value-format="yyyy/MM/dd">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="股东证件到期日" prop="gdidExpiry">
                  <el-date-picker
                    v-model="editForm.gdidExpiry"
                    type="date"
                    placeholder="股东证件登记日期"
                    value-format="yyyy/MM/dd">
                  </el-date-picker>
                </el-form-item>
                <el-form-item label="股东证件签发城市" prop="gdcnIdRegCity">
                  <!--<el-cascader
                    style="width:100%"
                    :options="citys"
                    v-model="editForm.gdcnIdRegCity"
                    @active-item-change="handleItemChange"></el-cascader>-->
                  <el-cascader
                    style="width:100%"
                    :options="cities"
                    v-model="editForm.gdcnIdRegCity"
                    :props="{ expandTrigger: 'hover',value:'value',label: 'label' }"
                  ></el-cascader>
                </el-form-item>
              </div>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="editDialogVisible = false">取消</el-button>
              <el-button type="primary" @click="doUploadFile"
                         v-loading.fullscreen.lock="fullscreenLoading">{{dialogStatus=='create'? '确定' : '修改'}}</el-button>
              <!--<el-button v-if="dialogStatus=='create'" type="primary" @click="doUploadFile"
                         v-loading.fullscreen.lock="fullscreenLoading">确定</el-button>
              <el-button v-else type="primary" @click="doEdit"
              v-loading.fullscreen.lock="fullscreenLoading">确定</el-button>-->
            </div>
          </el-dialog>

        </div>

      </div>
    </div>

    <!-- 联行号对话框 -->
    <el-dialog :visible.sync="UnionDialogVisible" title="选择行业分类" :close-on-click-modal="false"
               custom-class="customDialog">
      <el-form :model="listQuery1" status-icon label-position="left" class="demo-form-inline"
               label-width="100px" style="width: 100%; display: flex">
        <el-form-item label="行业分类名称" prop="interBankName">
          <el-input auto-complete="off" v-model="listQuery1.name" placeholder="行业分类名称" style="width:300px" />
        </el-form-item>
        <el-form-item>
          <el-button class="filter-item" type="primary" @click="queryUnio">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="unionnosLoading" :data="companys" element-loading-text="正在查询中。。。" border fit highlight-current-row
                :header-cell-style="{background:'#92D3FF',color:'#fff'}">
        <el-table-column align="left" min-width="100" label="行业分类名称" prop="name"/>
        <el-table-column align="center" label="操作" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="primary" size="mini"
                       @click="choose(scope.row)">选择
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="total1>0" :total="total1" :page.sync="listQuery1.pageNum" :limit.sync="listQuery1.pageSize"
                  @pagination="getIndustry"/>
    </el-dialog>
    <!--<div style="background: #000;height: 120px;"></div>-->

    <!---银行签约对话框--->
    <el-dialog :visible.sync="signingDialogVisible" title="银行签约" :close-on-click-modal="false" width="45%">
      <el-form ref="signForm" :rules="signFormRules" :model="signForm" status-icon label-position="left"
               label-width="165px" style="">
        <el-form-item label="签约银行：" prop="bankCode">
          <el-select v-model="signForm.bankCode" placeholder="请选择" style="width:50%" @change="bankNameChange">
            <el-option value="0000" label="富民银行">富民银行</el-option>
            <el-option value="0001" label="网商银行">网商银行</el-option>
            <el-option value="0002" label="振兴银行">振兴银行</el-option>
          </el-select>
          <el-alert
            v-if="signForm.bankCode == '0001' || signForm.bankCode == '0002'"
            style="background-color: #fff;padding: 0;width: 50%"
            title="即将上线"
            type="error"
            :closable="false">
          </el-alert>
          <el-alert
            v-if="bankCodes == signForm.bankCode && typeStatus == '0'"
            style="background-color: #fff;padding: 0;"
            title="此银行您已签约成功，无需再次签约！"
            type="error"
            :closable="false">
          </el-alert>
        </el-form-item>
        <el-form-item label="协议签署页扫描件：" prop="agreement" v-if="signForm.bankCode == '0000'">
          <el-upload
            style="width: 34%"
            class="upload-demo"
            ref="upload"
            action="string"
            :before-upload="beforeUploadFile"
            :http-request="dosigningUpload"
            :file-list="fileList"
            :limit="1"
            name="agreement"
            list-type="picture"
            accept=".jpg,.jpeg,.png,.JPG,.JPEG,.PBG,"
            :auto-upload="false">
            <el-button size="small" type="primary" style="width: 100%"
                       :disabled="signForm.bankCode == '0001' || bankCodes == signForm.bankCode && typeStatus == '0'">点击上传
            </el-button>
            <div slot="tip" class="el-upload__tip">图片文件（jpg、png、jpeg），2M以内</div>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="signForm.bankCode != '0000'"
            type="primary"
            @click="dosigningUpload"
            style="width: 50%"
            :disabled="signForm.bankCode == '0001' || signForm.bankCode == '0002' || bankCodes == signForm.bankCode && typeStatus == '0'">
            {{ accountStatus }}
          </el-button>
          <el-button
            v-else
            type="primary"
            @click="$refs.upload.submit()"
            style="width: 30%"
            :disabled="signForm.bankCode == '0001' || signForm.bankCode == '0002' || bankCodes == signForm.bankCode && typeStatus == '0'">
            {{ accountStatus }}
          </el-button>
        </el-form-item>
        <el-form-item style="padding: 20px 0 20px 0;" v-if="signForm.bankCode == '0000'">
          <el-button type="success" style="width: 30%" @click="agreementDownload" plain>
            协议下载
          </el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {doGet, doPost, doFile} from '@/api'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
import { typeCode } from '@/utils/type'
import { cities } from '@/utils/citys'

export default {
  name: 'compandsigning',
  components: { Pagination },
  filters: {},
  data() {
    let validateBackUploadFile = (rule, value, callback) => {
      let _this = this
      /*let uploadFiles = _this.$refs.Back.uploadFiles*/
      let uploadFiles = _this.editForm.legalIDBack
      let flag = uploadFiles && uploadFiles.length
      if (!flag) {
        callback(new Error('身份证反面不允许为空'))
      } else {
        callback()
      }
    }
    let validateFrontUploadFile = (rule, value, callback) => {
      let _this = this
      /*let uploadFiles = _this.$refs.Front.uploadFiles;*/
      let uploadFiles = _this.editForm.legalIDFront
      let flag = uploadFiles && uploadFiles.length
      if (!flag) {
        callback(new Error('身份证正面不允许为空'))
      } else {
        callback()
      }
    }
    let validatebusinessUploadFile = (rule, value, callback) => {
      let _this = this
      /*let uploadFiles = _this.$refs.business.uploadFiles*/
      let uploadFiles = _this.editForm.businessLicense
      let flag = uploadFiles && uploadFiles.length
      if (!flag) {
        callback(new Error('企业统一执照不允许为空'))
      } else {
        callback()
      }
    }
    return {
      cities: cities,
      list: [],
      citys: [],
      countys: [],
      total1: 0,
      unicodes: [],
      companys: [],
      CodeList: [],
      uniList: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        pageSize: 20,
      },
      editForm: {
        unicode: undefined,
        companyName: undefined,
        province: undefined,
        address: undefined,
        postcode: undefined,
        industry: undefined,
        industryName: undefined,
        typeCode: '',
        detailCode: '',
        loanCardNo: undefined,
        legalIDFront: undefined,
        legalIDBack: undefined,
        legalName: undefined,
        legalID: undefined,
        legalMobile: undefined,
        legalIDRegDate: undefined,
        legalIDExpiry: undefined,
        legalIDCity: undefined,
        businessLicense: undefined,
        certRegDate: undefined,
        certExpiryDate: undefined,
        certRegCity: undefined,
        procode: undefined,
        proname: undefined,
        gdcnIdRegCity: undefined,
        gdcustomerName: undefined,
        gdcertId: undefined,
        gdregDate: undefined,
        gdidExpiry: undefined,
        provinceNa: undefined,  //
        provinceCod: undefined,
        legalIDCityNa: undefined,
        legalIDCityCod: undefined,
        certRegCityNa: undefined,
        certRegCityCod: undefined,
        gdcnIdRegAndCity: undefined,
        legalIDAndCity: undefined
      },
      editFormRules: {
        unicode: [{required: true, message: '统一信用代码不允许为空', trigger: 'blur'}],
        companyName: [{required: true, message: '公司名称不允许为空', trigger: 'blur'}],
        province: [{required: true, message: '公司所属省份不允许为空', trigger: 'blur'}],
        address: [{required: true, message: '公司详细地址不允许为空', trigger: 'blur'}],
        postcode: [{required: true, message: '邮政编码不允许为空', trigger: 'blur'}],
        industry: [{required: true, message: '行业分类不允许为空', trigger: 'blur'}],
        loanCardNo: [{required: true, message: '中征码不允许为空', trigger: 'blur'}],
        legalIDFront: [{required: true, trigger: 'blur', validator: validateFrontUploadFile}],
        legalIDBack: [{required: true, trigger: 'blur', validator: validateBackUploadFile}],
        businessLicense: [{required: true, trigger: 'blur', validator: validatebusinessUploadFile}],
        legalName: [{required: true, message: '法人姓名不允许为空', trigger: 'blur'}],
        legalID: [{required: true, message: '法人证件号码不允许为空', trigger: 'blur'}],
        legalMobile: [{required: true, message: '法人手机号不允许为空', trigger: 'blur'}],
        legalIDRegDate: [{required: true, message: '法人证件登记日期不允许为空', trigger: 'blur'}],
        legalIDExpiry: [{required: true, message: '法人证件到期日期不允许为空', trigger: 'blur'}],
        legalIDCity: [{required: true, message: '法人证件签发城市不允许为空', trigger: 'blur'}],
        certRegDate: [{required: true, message: '执照证件注册日期不允许为空', trigger: 'blur'}],
        certExpiryDate: [{required: true, message: '执照证件到期日期不允许为空', trigger: 'blur'}],
        gdcustomerName: [{required: true, message: ' 股东名称不允许为空', trigger: 'blur'}],
        gdcertId: [{required: true, message: '股东证件编号不允许为空', trigger: 'blur'}],
        gdregDate: [{required: true, message: '股东证件登记日期不允许为空', trigger: 'blur'}],
        gdidExpiry: [{required: true, message: '股东证件到期日不允许为空', trigger: 'blur'}],
        gdcnIdRegCity: [{required: true, message: '股东证件签发城市不允许为空', trigger: 'blur'}]
      },
      editDialogVisible: false,
      textMap: {
        update: '编辑',
        create: '添加企业信息',
        signing: '签约银行'
      },
      dialogStatus: undefined,
      fileList: [],
      frontFileList: [],      //身份证正面
      backFileList: [],       //身份证反面
      businessFileList: [],   //企业执照
      typeCode: typeCode,
      editIndex: undefined,
      fullscreenLoading: false,
      UnionDialogVisible: undefined,
      unionnosLoading: true,
      listQuery1: {
        pageNum: 1,
        pageSize: 10,
        name: undefined
      },
      signingDialogVisible: false,
      signForm: {
        bankCode: undefined,
        id: undefined,
        unicode: undefined
      },
      signFormRules: {
        bankCode: [{ required: true, message: '签约银行不允许为空', trigger: 'blur' }],
      },
      accountStatus: '签约',
      bankCodes: undefined,
      typeStatus: undefined,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      doGet('company.html?op=list').then(response => {
        this.list = response.rows
        /**this.total = response.data.totalcount*/
        this.listLoading = false
      }).catch(() => {
        this.list = []
        /**this.total = 0*/
        this.listLoading = false
      })
    },
    getIndustry() {
      this.UnionDialogVisible = true
      this.unionnosLoading = true
      this.listQuery1.name = ''
      doGet('company.html?op=getIndustryList', this.listQuery1).then(response => {
        this.companys = response.rows
        this.total1 = response.data.totalcount
        this.unionnosLoading = false
      }).catch(() => {
        this.companys = []
        this.total1 = 0
        this.unionnosLoading = false
      })
    },
    getDetail() {
      doGet('company.html?op=getDetailCodeList').then(response => {
        this.CodeList = response.rows
      }).catch(() => {
        this.CodeList = []
      })
    },
    unicodeList() {
      doGet('company.html?op=getCurrentUserCompany', this.listQuery).then(response => {
        this.unicodes = response.rows
      }).catch(() => {
        this.unicodes = []
      })
    },
    handleAdd() {
      if (!this.citys.length) {
        this.provinceList()
      }
      this.getDetail()
      this.editForm = {
        unicode: undefined,
        companyName: undefined,
        province: undefined,
        address: undefined,
        postcode: undefined,
        industryName: undefined,
        industry: undefined,
        typeCode: '',
        detailCode: '',
        loanCardNo: undefined,
        legalIDFront: undefined,
        legalIDBack: undefined,
        legalName: undefined,
        legalID: undefined,
        legalMobile: undefined,
        legalIDRegDate: undefined,
        legalIDExpiry: undefined,
        legalIDCity: undefined,
        businessLicense: undefined,
        certRegDate: undefined,
        certExpiryDate: undefined,
        certRegCity: undefined,
        gdcnIdRegCity: undefined,
        gdcustomerName: undefined,
        gdcertId: undefined,
        gdregDate: undefined,
        gdidExpiry: undefined,
        provinceNa: undefined,  /**==*/
        provinceCod: undefined,
        legalIDCityNa: undefined,
        legalIDCityCod: undefined,
        certRegCityNa: undefined,
        certRegCityCod: undefined,
        legalIDAndCity: undefined,
        gdcnIdRegAndCity: undefined
      }
      this.frontFileList = []
      this.backFileList = []
      this.businessFileList = []
      this.editDialogVisible = true
      this.dialogStatus = 'create'
      this.$nextTick(() => {
        this.$refs['editForm'].clearValidate()
      })
    },
    beforeUploadFile(file) {
      this.file = file;
      let extension = file.name.substring(file.name.lastIndexOf('.') + 1)
      let size = file.size / 1024 / 1024 <= 2
      if (extension !== 'jpg' && extension !== 'png' && extension !== 'jpeg' && extension !== 'JPG' && extension !== 'PNG') {
        this.$notify.warning({
          title: '警告',
          message: `只能上传png（即后缀是.jpg或.png）的图片`
        })
        return false
      }
      if (!size) {
        this.$notify.error({
          title: '失败',
          message: `请上传小于2MB的图片`
        })
        return false
      }
    },

    doLicenseUpload(param) {
      var fd = new FormData()
      fd.append('pic', param.file)
      doFile('uploadPic.html', fd).then((res) => {
        this.editForm.businessLicense = res.data.picpath
      }).catch(response => {
        this.$notify.error({
          title: '失败',
          message: response.message
        })
      })
    },
    doFrontUpload(param) {
      var fd = new FormData()
      fd.append('pic', param.file)    //传文件
      doFile('uploadPic.html', fd).then((res) => {
        this.editForm.legalIDFront = res.data.picpath
      }).catch(response => {
        this.$notify.error({
          title: '失败',
          message: response.message
        })
      })
    },
    doBackUpload(param) {
      var fd = new FormData()
      fd.append('pic', param.file)
      doFile('uploadPic.html', fd).then((res) => {
        this.editForm.legalIDBack = res.data.picpath
      }).catch((response) => {
        this.$notify.error({
          title: '失败',
          message: response.message
        })
      })
    },
    doUploadFile() {
      /**最后我们做表单验证，数据ok就允许提交，同时也别忘了前几步图片为空的时候的表单验证哦~*/
      this.$refs['editForm'].validate(valid => {
        if (valid) {
          let fd = new FormData()
          this.fullscreenLoading = true
          fd.append('businessLicense', this.editForm.businessLicense)
          fd.append('legalIDFront', this.editForm.legalIDFront)
          fd.append('legalIDBack', this.editForm.legalIDBack)
          fd.append('unicode', this.editForm.unicode)
          fd.append('companyName', this.editForm.companyName)
          fd.append('province', this.editForm.province)
          // fd.append('provinceNa', this.editForm.province[0])
          // fd.append('provinceCod', this.editForm.province[1])
          fd.append('address', this.editForm.address)
          fd.append('postcode', this.editForm.postcode)
          fd.append('industry', this.editForm.industry)
          fd.append('typeCode', this.editForm.typeCode)
          fd.append('detailCode', this.editForm.detailCode)
          fd.append('loanCardNo', this.editForm.loanCardNo)
          fd.append('legalName', this.editForm.legalName)
          fd.append('legalID', this.editForm.legalID)
          fd.append('legalMobile', this.editForm.legalMobile)
          fd.append('legalIDRegDate', this.editForm.legalIDRegDate)
          fd.append('legalIDExpiry', this.editForm.legalIDExpiry)
          fd.append('legalIDCity', this.editForm.legalIDCity)
          // fd.append('legalIDCityNa', this.editForm.legalIDAndCity[0])
          // fd.append('legalIDCityCod', this.editForm.legalIDAndCity[1])
          // fd.append('legalIDCity', this.editForm.legalIDAndCity[2])
          fd.append('certRegDate', this.editForm.certRegDate)
          fd.append('certExpiryDate', this.editForm.certExpiryDate)
          fd.append('gdcustomerName', this.editForm.gdcustomerName)
          fd.append('gdcertId', this.editForm.gdcertId)
          fd.append('gdregDate', this.editForm.gdregDate)
          fd.append('gdidExpiry', this.editForm.gdidExpiry)
          fd.append('gdcnIdRegCity', this.editForm.gdcnIdRegCity)
          // fd.append('certRegCityNa', this.editForm.gdcnIdRegAndCity[0])
          // fd.append('certRegCityCod', this.editForm.gdcnIdRegAndCity[1])
          // fd.append('gdcnIdRegCity', this.editForm.gdcnIdRegAndCity[2])
          // fd.append('op', 'addcompany')
          fd.append('op', `${this.dialogStatus == 'create' ? 'addcompany' : 'chgcompany'}`)
          doFile('company.html', fd).then((res) => {
            this.getList()
            this.editDialogVisible = false
            this.list[this.editIndex] = this.editForm
            this.$notify.success({
              title: '成功',
              message: this.dialogStatus == 'create' ? '注册公司成功' : '修改成功'
            })
            this.fullscreenLoading = false
          }).catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.message
            })
            this.fullscreenLoading = false
          })
        }
      })
    },
    /*弹出修改窗口*/
    handleEdit(row) {
      this.getDetail()
      this.editForm = Object.assign({}, row)
      // this.editIndex = this.list.indexOf(row)
      this.dialogStatus = 'update'
      this.editDialogVisible = true
      this.editForm.province = row.province.split(',')
      this.editForm.legalIDCity = row.legalIDCity.split(',')
      this.editForm.gdcnIdRegCity = row.gdcnIdRegCity.split(',')
      this.editForm.legalIDFront = row.legalIDFront
      this.editForm.legalIDBack = row.legalIDBack
      this.editForm.businessLicense = row.businessLicense
      this.frontFileList = []
      this.backFileList = []
      this.businessFileList = []
      let obj1 = new Object()
      let obj2 = new Object()
      let obj3 = new Object()
      obj1.url = row.legalIDFront.replace('C:/data/', 'pic/')
      obj2.url = row.legalIDBack.replace('C:/data/', 'pic/')
      obj3.url = row.businessLicense.replace('C:/data/', 'pic/')
      this.frontFileList.push(obj1)
      this.backFileList.push(obj2)
      this.businessFileList.push(obj3)
      this.$nextTick(() => {
        this.$refs['editForm'].clearValidate()
      })
      if (!this.citys.length) {
        this.provinceList()
      } else {
        let cityArr = this.citys.filter(item => {
          return row.procode == item.value
        })[0]
        if (cityArr && !cityArr.children.length) {
          doGet('company.html?op=getProvinceData', { flag: 2, procode: cityArr.value }).then(response => {
            this.citys.forEach(item => {
              if (item.value == cityArr.value) {
                item.children = response.rows.map(items => {
                  return {
                    value: items.procode,
                    label: items.proname
                  }
                })
              }
            })
          }).catch(() => {
          })
        }
      }
    },
    doEdit() {
      this.$refs['editForm'].validate(valid => {
        if (valid) {
          this.fullscreenLoading = true
          let sendData = {
            ...this.editForm,
            // provinceNa: this.editForm.province[0],
            // provinceCod: this.editForm.province[1],
            province: this.editForm.province,
            // legalIDCityNa: this.editForm.legalIDAndCity[0],
            // legalIDCityCod: this.editForm.legalIDAndCity[1],
            legalIDCity: this.editForm.legalIDCity,
            // legalIDAndCity: undefined,
            // certRegCityNa: this.editForm.gdcnIdRegCity[0],
            // certRegCityCod: this.editForm.gdcnIdRegCity[1],
            gdcnIdRegCity: this.editForm.gdcnIdRegCity,
            // gdcnIdRegAndCity: undefined,
            legalIDFront: this.editForm.legalIDFront,
            legalIDBack: this.editForm.legalIDBack,
            businessLicense: this.editForm.businessLicense
          }
          doGet('company.html?op=chgcompany', sendData)
            .then(response => {
              this.getList()
              this.editDialogVisible = false
              this.list[this.editIndex] = this.editForm
              this.$notify.success({
                title: '成功',
                message: '修改成功'
              })
              this.fullscreenLoading = false
            })
            .catch(response => {
              this.$notify.error({
                title: '失败',
                message: response.message
              })
              this.fullscreenLoading = false
            })
        }
      })
    },
    //省城市
    provinceList() {
      doGet('company.html?op=getProvinceData', { flag: 1 }).then(response => {
        this.citys = response.rows.map(item => {
          return {
            value: item.procode,
            label: item.proname,
            children: []
          }
        })
        if (this.dialogStatus == "update") { // 修改信息执行
          let cityArr = this.citys.filter(item => {
            return this.editForm.province == item.value
          })[0]
          if (cityArr && !cityArr.children.length) {
            doGet('company.html?op=getProvinceData', { flag: 2, procode: cityArr.value }).then(response => {
              this.citys.forEach(item => {
                if (item.value == cityArr.value) {
                  item.children = response.rows.map(items => {
                    return {
                      value: items.procode,
                      label: items.proname
                    }
                  })
                }
              })
            }).catch(() => {

            })
          }
        }
      }).catch(() => {
        this.citys = []
      })
    },
    /*触发一级显示二级*/
    handleItemChange(val) {
      let cityArr = this.citys.filter(item => {
        return item.value == val
      })[0]
      if (!cityArr.children.length) {
        doGet('company.html?op=getProvinceData', { flag: 2, procode: cityArr.value }).then(response => {
          this.citys.forEach(item => {
            if (item.value == val) {
              item.children = response.rows.map(items => {
                return {
                  value: items.procode,
                  label: items.proname,
                }
              })
            }
          })
        }).catch(() => {
        })
      }
    },
    signingAdd(row) {
      this.signingDialogVisible = true
      // this.signForm.id = row.id
      this.signForm.unicode = row.unicode
      this.getNavType()
    },
    doDelete(row) {
      doGet('company.html?op=del', {unicode: row.unicode})
        .then(response => {
          this.$notify.success({
            title: '成功',
            message: '删除成功'
          })
          const index = this.list.indexOf(row)
          this.list.splice(index, 1)
          this.$refs[`popover-` + row.unicode].doClose()
          this.total--
        })
        .catch(response => {
          this.$notify.error({
            title: '失败',
            message: response.message
          })
        })
    },
    dosigningUpload(param) {
      this.$refs['signForm'].validate(valid => {
        if (valid) {
          let fd = new FormData()
          fd.append('agreement', param.file)    // 上传文件
          fd.append('bankCode', this.signForm.bankCode)
          fd.append('unicode', this.signForm.unicode)
          fd.append('op', `${this.accountStatus == '签约' ? 'sign' : 'resign'}`)
          doPost('company.html', fd).then(response => {
            this.$notify.success({
              title: '成功',
              message: this.accountStatus == '签约' ? '操作成功' : '重新签约提交成功'
            })
            if (this.$refs['signForm'] !== undefined) {
              this.$refs['signForm'].resetFields()
            }
            this.signingDialogVisible = false
          }).catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.message
            })
            this.signingDialogVisible = false
          })
        }
      })
    },
    getNavType() {
      doGet('company.html?op=signresult', { unicode: this.signForm.unicode }).then(response => {
        this.uniList = response.rows
        for (var item of response.rows) {
          this.typeStatus = item.status
          this.bankCodes = item.bankCode
        }
      }).catch(() => {
        this.uniList = []
      })
    },
    /**切换按钮*/
    bankNameChange() {
      for (var item of this.uniList) {
        if (this.signForm.bankCode == item.bankCode && item.status == '2') {
          this.accountStatus = '重新签约'
        }
      }
    },
    /**协议下载*/
    agreementDownload() {
      var url ='http://www.piaojupingtai.com/'
      /*url += 'downLoad.html?bankCode=' + this.sigingInfo.bankCode + '&op=download'*/
      url += 'downLoad.html?op=download&' + this.signForm.bankCode
      window.open(url)
    },
    /*分行查找*/
    queryUnio() {
      this.UnionDialogVisible = true
      this.pageNum = this.pageNum
      this.pageSize = this.pageSize
      this.getIndustry()
    },
    /*选择分行*/
    choose(row) {
      this.editForm.industry = row.number
      this.editForm.industryName = row.name
      this.listQuery1.name = row.name
      this.UnionDialogVisible = false
    },
  }
}
</script>
<style lang="scss" scoped>
  .dashboard-editor-container {
    padding: 200px 0px 0px;
    background-color: #f7f7f7;
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;

    .chart-wrapper {
      background: #fff;
      padding: 16px 16px 0;
      margin-bottom: 32px;
    }
  }
</style>
